/**
 * Description: 设备管理Api
 *
 * Created by hrx on 2023/7/19
 */
import service, {IResponseArrayDto, IResponseDto} from "@/utils/ajax";
import type {IBaseQueryDataListParams} from "@/api/index"
import {AxiosResponse} from "axios";

export interface queryDeviceListParam {
  deviceCode?: string,
  regionList?: Array<number>,
  productIdList?: Array<number>,
  regionIdList?: Array<Array<number>>,
}

export interface deviceDetailDTO {
  id: number,
  deviceCode?: string,
  productId?: number,
  productName?: string,
  deviceName?: string,
  regionId?: number,
  regionPositionId?: string,
  regionLevelGroupName?: string,
  regionName?: string,
  positionName?: string,
  deviceStatus?: number,
  lastCommunicationTime?: string,
  createTime?: string,
  regionList?: Array<number>
}

export interface deviceModelDTO {
  productId?: number,
  productName?: string,
  productModel?: string
}

export interface regionTreeDTO {
  id?: number,
  regionName?: string,
  parentId?: number,
  regionRemark?: string,
  regionClassify?: number
  children?: Array<regionTreeDTO>
}

export interface regionPositionDTO{
  id?: number,
  positionName?: string
}


// 设备列表
export function getDeviceListApi(data: IBaseQueryDataListParams<queryDeviceListParam>): Promise<IResponseDto<IResponseArrayDto<deviceDetailDTO>>> {
  return service({
    url: '/cloud/device/queryPage',
    method: "post",
    data,
    headers: {"showLoading": true},
  })
}

// 创建设备
export function createDeviceApi(data: deviceDetailDTO): Promise<AxiosResponse<IResponseDto>> {
  return service({
    url: '/cloud/device/create',
    method: "post",
    data,
    headers: {"showLoading": true},
  })
}

// 删除设备
export function delDeviceApi(id: number): Promise<AxiosResponse<IResponseDto>> {
  return service({
    url: `/cloud/device/deleteById/${id}`,
    method: "get",
    data: {},
    headers: {"showLoading": true},
  })
}

// 编辑设备
export function editDeviceApi(data: deviceDetailDTO): Promise<AxiosResponse<IResponseDto>> {
  return service({
    url: '/cloud/device/update',
    method: "post",
    data,
    headers: {"showLoading": true},
  })
}

// 所在区域下拉框
export function getRegionTreeApi(): Promise<AxiosResponse<IResponseDto<Array<regionTreeDTO>>>> {
  return service({
    url: '/cloud/device/selectRegionTree',
    method: "post",
    data: {},
    headers: {"showLoading": true},
  })
}

// 设备型号下拉框
export function getDeviceModelApi(): Promise<AxiosResponse<IResponseDto<Array<deviceModelDTO>>>> {
  return service({
    url: '/cloud/device/selectDeviceModel',
    method: "post",
    data: {},
    headers: {"showLoading": true},
  })
}

// 安装点位下拉框
export function getRegionPositionApi(id: number | undefined): Promise<AxiosResponse<IResponseDto<Array<regionPositionDTO>>>> {
  return service({
    url: `/cloud/device/selectRegionPosition/${id}`,
    method: "get",
    data: {},
    headers: {"showLoading": false},
  })
}

// 上传设备api
export function uploadDeviceApi(data: any): Promise<AxiosResponse<IResponseDto>> {
  return service({
    url: '/cloud/device/importDevice',
    method: "post",
    data,
    headers: {
      'Content-Type': 'multipart/form-data;',
      "showLoading": true
    },
  })
}
